<?php
//开启session
// session_start();
 
		 $id = $_GET['id'];

 
		if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){

			 // 查询要删除的分类是否有子级

		 $sql = "select * from `cate` where pid = $id";

		 // 执行
		 $result = mysqli_query($link,$sql);
		// 如果有

		  echo ($result->num_rows>0)?1:0;
		  die;


		}


           $row = getCatedel($id);


           if ($row>0) {
    echo '<script> alert ("删除成功");location.href="index.php?c=cate&a=list&admin=1";</script>';die;
       
}else{

    echo '<script> alert ("删除失败");history.go(-1);</script>';
        die;
}


     function getCatedel($pid=0){


              $sql = "select * from `cate` where pid=$pid";
                  // 执行语句
                $result = mysqli_query($GLOBALS['link'],$sql);


                if($result->num_rows>0){
	         while($arr = mysqli_fetch_assoc($result)){

                // $id = $arr['id'];

               getCatedel($arr['id']);

                          } 

                      }

      return  del($GLOBALS['c'],$pid);
                 }




















?>

